package com.zqxq.lottery.api.config;

import com.zqxq.common.utils.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@Configuration
public class FileVirtualPathConfig extends WebMvcConfigurerAdapter {
    @Autowired
    private FileConfig fileConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (StrUtils.isEmpty(fileConfig.getImage_dns())) {
            registry.addResourceHandler("/ZQXQ-LOTTERY/image/**").addResourceLocations("file:"+fileConfig.getFile_diskPath_public()+"ZQXQ-LOTTERY/image/");
            registry.addResourceHandler("/ZQXQ-LOTTERY/data/**").addResourceLocations("file:"+fileConfig.getFile_diskPath_public()+"ZQXQ-LOTTERY/data/");
        }
        else{
            registry.addResourceHandler("/ZQXQ-LOTTERY/image/**").addResourceLocations(fileConfig.getImage_dns()+"/ZQXQ-LOTTERY/image/");
            registry.addResourceHandler("/ZQXQ-LOTTERY/data/**").addResourceLocations(fileConfig.getImage_dns()+"/ZQXQ-LOTTERY/data/");
        }
        super.addResourceHandlers(registry);
    }
}
